<?php
namespace Ntxx\Controller;
use Think\Controller;
class AdminController extends Controller {
	public function _initialize(){
		if(!session('?admin')){
			redirect(U('Login/index'));
		}
		define('ADMIN',session('admin'));
		$this->assign('user',session('admin'));
	}
	
	public function upload(){
		//echo $path;
		//$path = '/Public/upload/';
		$path ='./upload/ntxx/';
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   =     2048000 ;// 设置附件上传大小
		$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->mimes      =     array('image/png', 'image/jpeg', 'image/gif');// 设置附件上传类型
		$upload->rootPath  =     $path; // 设置附件上传根目录
		$upload->savePath  =     ''; // 设置附件上传（子）目录
		$info   =   $upload->uploadOne($_FILES['img']);
		if(!$info) {// 上传错误提示错误信息
			//if(!$data['id'])
				//$this->error($upload->getError());
			//unset($data['photo']);
			$this->ajaxReturn(array('status'=>0,'info'=>$upload->getError()),'json');
		}else{// 上传成功
			$this->ajaxReturn(
				array(
					'status'=>1,
					'img'=>'http://game.jjcbw.com/upload/ntxx/'.$info['savepath'].$info['savename'],
					'info'=>'上传成功',
				),
				'json'
			);
			//md5_file可以获得文件MD5
		}
		$this->ajaxReturn(array('status'=>1,'info'=>'未知错误'),'json');
	}
	
	public function uploadmp3(){
		//echo $path;
		//$path = '/Public/upload/';
		$path ='./upload/ntxx/';
		//exit($path);
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   =     5120000 ;// 设置附件上传大小
		$upload->exts      =     array('mp3');// 设置附件上传类型
		$upload->mimes      =     array('audio/mp3');// 设置附件上传类型
		$upload->rootPath  =     $path; // 设置附件上传根目录
		$upload->savePath  =     ''; // 设置附件上传（子）目录
		$info   =   $upload->uploadOne($_FILES['mp3']);
		if(!$info) {// 上传错误提示错误信息
			//if(!$data['id'])
				//$this->error($upload->getError());
			//unset($data['photo']);
			$this->ajaxReturn(array('status'=>0,'info'=>$upload->getError()),'json');
		}else{// 上传成功
			$this->ajaxReturn(
				array(
					'status'=>1,
					'mp3'=>'http://game.jjcbw.com/upload/ntxx/'.$info['savepath'].$info['savename'],
					'info'=>'上传成功',
				),
				'json'
			);
			//md5_file可以获得文件MD5
		}
		$this->ajaxReturn(array('status'=>1,'info'=>'未知错误'),'json');
	}
}